import * as API from '../services/data';

export default {
    state: {},
    reducers: {
        setdataSource(state, { result }) {
            return {
                ...state,
                dataSource: result.RESPONSE,
            }
        }
    },
    effects: {
        *query({ data }, { call, put }) {
            const result = yield call(API.query, { ...data });
            yield put({ type: "setdataSource", result }) //用来触发上面的reducers
            return result;

            //axios  处理多个并请求
            // axios.all([
            //     API.query(data),
            //     API.queryy(data),
            // ]).then(axios.spread((result, res2) => {
            //     window.g_app._store.dispatch({ type: "data/setdataSource", result });//此处的data是文件名
            //     return result;
            // }));   
        },
        *insetorupdate({ data }, { call }) {
            const result = yield call(API.insetorupdate, { ...data });
            return result;
        },
        *delete({ data }, { call }) {
            const result = yield call(API.deletebyid, { ...data });
            return result;
        }
    }
}